from fastapi import Request, Response
from fastapi.routing import APIRoute
from afast_core.core_libs.classy_apirouter.group_router import RestInjectForAPIRouter, RestInjectForDocRouter
from infirmary_admin_src.infirmary_common.infirmary_controller import IBaseController
from afast_core.core_libs.classy_apirouter import IHookGroupBaseController
from afast_core.core_libs.classy_apirouter import get, post
from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.system.menu.controllers.auth_url import \
    SystemMenuAuthUrlController
from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.system.menu.controllers.menu_add import \
    SystemMenuAddController
from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.system.menu.controllers.menu_batchdelete import \
    SystemMenuBatchdeleteController
from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.system.menu.controllers.menu_query import \
    SystemMenuQueryController
from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.system.menu.controllers.menu_tree import \
    SystemMenuTreeController
from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.system.menu.controllers.menu_update import \
    SystemMenuUpdateController


#  tags=['测试类装饰器依赖项']

@RestInjectForAPIRouter(prefix='/menu')
@RestInjectForDocRouter(tags=['后台系统-菜单模块'])
class AGroupAPIRouterBuilder(IHookGroupBaseController):
    # 定义公共全局的可用的服务，通过request对象进行透传当前的self

    async def before_request(self, curr_apiroute: APIRoute, request: Request) -> None:
        """如果需要修改请求信息，可直接重写此方法"""
        pass
        request.state.api_router_builder = self
        # 如果存在body对象的，在这里读取一下，以备后续的使用
        request.state.schema_param_body = await request.body()
        print("request.state.schema_param_body ", request.state.schema_param_body)

    async def after_request(self, request: Request, response: Response) -> None:
        """请求后的处理"""
        pass

    @get("/query", summary='菜单模块-菜单列表信息获取')
    def admin_menu_query(self, controller: IBaseController = SystemMenuQueryController):

        return controller.sync_response()

    @get("/auth/url", summary='菜单模块-获取列表查询')
    def admin_menu_auth_url(self, controller: IBaseController = SystemMenuAuthUrlController):

        return controller.sync_response()

    @get("/tree", summary='菜单模块-获取树形菜单列表')
    def admin_menu_tree(self, controller: IBaseController = SystemMenuTreeController):
        return controller.sync_response()

    @get("/batchDelete", summary='菜单模块-删除菜单')
    def admin_menu_batchdelete(self, controller: IBaseController = SystemMenuBatchdeleteController):
        return controller.sync_response()

    @post("/update", summary='菜单模块-菜单更新')
    def admin_menu_update(self, controller: IBaseController = SystemMenuUpdateController):
        return controller.sync_response()

    @post("/add", summary='菜单模块-菜单添加')
    def admin_menu_add(self, controller: IBaseController = SystemMenuAddController):
        return controller.sync_response()

